package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.constant.PageResult;
import com.itheima.constant.QueryPageBean;
import com.itheima.dao.CheckItemDao;
import com.itheima.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemImplServiceImpl implements CheckItemService {
    @Autowired
    public CheckItemDao checkItemDao;
    @Override
    public void add(CheckItem checkItem) {
        checkItemDao.add(checkItem);
    }

//    分页查询
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<CheckItem>page=checkItemDao.selectByString(queryString);
        long total = page.getTotal();
        List<CheckItem> rows = page.getResult();
        return new PageResult(total,rows);
    }

//    根据id删除
    @Override
    public void deleteById(Integer id) {
        if(checkItemDao.findCountBycheckID(id)>0){
            new RuntimeException("不能被删除");
        }
        checkItemDao.deleteById(id);
    }
//编辑
    @Override
    public void edit(CheckItem checkItem) {
        checkItemDao.edit(checkItem);
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<CheckItem> findAll() {
        List<CheckItem> res=checkItemDao.findAll();
        return res;
    }
}
